<?php
class CompanyAction extends Action {

	public function index(){
		$rs=pageing('company',10,'',$_GET['seach'],'company_id desc','1','company_name');
		foreach($rs['data'] as $val){
			$val['time_insert']=date('Y-m-d H:i');
			$arr[]=$val;	
		}
		$rs['data']=$arr;
		$this->assign("rs",$rs);
		$this->display();
	}
	
	
	//添加公司后台管理员
	public function admin(){
		$rs=pageing('admin',10,'',$_GET['seach'],'admin_id desc','admin_cid='.$_GET['cid'],'admin_name');
		$this->assign('rs',$rs);
		$this->display();
	}

	public function add_company_admin(){
        if(!D('Admin')->add_admin($_POST))
            $this->error('添加失败');
        $this->success('添加成功');
	}
	
	//添加企业
	public function addAct(){
        if(!D('Company')->add_company($_POST))
            $this->error('添加失败');
        $this->success('添加成功');
	}

	public function choose_app()
	{
		$list = M('teamin_app','','')->db(1,'DB_CONFIG2')->where('app_openUrl!="TeamInHome" and app_project="Teamin"')->select();
		$this->assign('speakerlist',$list);
		$this->display();
	}

	public function add_app()
	{
		M('company_app_rds','','')->db(1,'DB_CONFIG1')->where('cid='.$_POST['company_id'])->delete();
		foreach($_POST['choose'] as $val)
		{
			$data['app_id'] = $val;
			$data['cid'] 	= $_POST['company_id'];
			M('company_app_rds','','')->db(1,'DB_CONFIG1')->add($data);
		}
		echo "<script>alert('分配成功');window.close();</script>";
	}

}